
/*========================================================================================
 *                                                                                      *
 *               Copyright(c) 2013-2014, Cha SangWoo, All rights reserved.              *
 *                                                                                      *
 * This file is part of ChaOS.                                                          *
 *                                                                                      *
 * Permission to use, copy, modify, and distribute this software in source and binary   *
 * forms and its documentation for any purpose and without fee is hereby granted,       *
 * provided that the above copyright notice appear in all copies and that both that     *
 * copyright notice and this permission notice appear in supporting documentation.      *
 *                                                                                      *
 * THIS SOFTWARE IS PROVIDED BY THE CHA SANGWOO AND CONTRIBUTORS "AS IS" AND ANY        *
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED            *
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   *
 * IN NO EVENT SHALL CHA SANGWOO OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,    *
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT         *
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,          *
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF            *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE      *
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,                    *
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                   *
 *                                                                                      *
========================================================================================*/

#ifndef __CO_DATA_TYPE_H__
#define __CO_DATA_TYPE_H__

#ifdef __cplusplus
    extern "C" {
    namespace ChaOS {
#endif

#include "co_port_config.h"

//////////////////////////////////////  < BEGIN >  ///////////////////////////////////////

/*======================================================================================*/
/*
    Compiler type definition
*/
/*======================================================================================*/

#if   defined (WIN32)               /* Windows */
    #define __CO_FUNC__             __FUNCTION__
    #define __CO_LINE__             __LINE__
    #define __CO_FILE__             __FILE__

    typedef int                     BOOL;           // type for boolean

#elif defined (COMPILER_RVDS)
    #define __CO_FUNC__             __func__
    #define __CO_LINE__             __LINE__
    #define __CO_FILE__             __FILE__

    typedef unsigned char           BOOL;           // type for boolean

#elif defined (__CC_ARM)            /* Keil uVision */
    #define __CO_FUNC__             __func__
    #define __CO_LINE__             __LINE__
    #define __CO_FILE__             __FILE__

    typedef unsigned char           BOOL;           // type for boolean

#elif defined (COMPILER_ROWLEY)
    #define __CO_FUNC__            ""
    #define __CO_LINE__             __LINE__
    #define __CO_FILE__             __FILE__
    //#define __FUNC__             __LINE__##__FILE__

    typedef unsigned char           BOOL;           // type for boolean
 
#elif defined (__ICCARM__)          /* IAR EWARM */
    #define __CO_FUNC__             __func__
    #define __CO_LINE__             __LINE__
    #define __CO_FILE__             __FILE__

    typedef unsigned char           BOOL;           // type for boolean    
    
#else
    #error "__ must define Compiler Type __"

#endif


/*======================================================================================*/
/*
    Constant type definition
*/
/*======================================================================================*/
#if           (MCU_FAMILY == MAXQ30)
    #define CONST           const __code

#elif defined (MCU_FAMILY)
    #define CONST           const

#else
    #error "__ must define family and model for MCU __"

#endif

/*======================================================================================*/
/*
    Basic data type definition
*/
/*======================================================================================*/

// type for byte
typedef unsigned char           BYTE;

// type for character type
typedef          char           CHAR;

// type for word unsigned value
typedef unsigned int            UINT;

// type for word signed value
typedef          int            INT;


/*======================================================================================*/
/*
    Integer data type definition
*/
/*======================================================================================*/

// type for 8 bit integer value
typedef unsigned char           UINT8;
typedef          char           INT8;

// type for 16 bit integer value
typedef unsigned short          UINT16;
typedef          short          INT16;

// type for 32 bit integer value
typedef unsigned int            UINT32;
typedef          int            INT32;


/*======================================================================================*/
/*
    Etc data type definition
*/
/*======================================================================================*/

// type for object control block
typedef unsigned int            OBJECT;

// type for void
#define VOID                    void

// result of ChaOS
typedef UINT8                   CO_RESULT; 

/*======================================================================================*/
/*
    Const value definition
*/
/*======================================================================================*/

// type for null
#ifndef NULL
#define NULL                    (0)
#endif

// type for false
#ifndef FALSE
#define FALSE                   0
#endif

// type for true
#ifndef TRUE
#define TRUE                    1
#endif

#define WAIT_NONE               (0)
#define WAIT_FOREVER            (0xFFFF)


/*======================================================================================*/
/*
    CO_RESULT value definition
*/
/*======================================================================================*/

#define CO_OK_SUCCESS           ((UINT8)  0)
#define CO_NG_USED              ((UINT8)  1)
#define CO_NG_TIMEOUT           ((UINT8)  2)
#define CO_NG_RESET             ((UINT8)  3)
#define CO_NG_SYNC              ((UINT8)  4)

#define CO_NG_QUEUE_EMPTY       ((UINT8) 10)
#define CO_NG_QUEUE_FULL        ((UINT8) 11)

// entry point of thread
typedef INT  (*THREAD_PROC)(UINT arg);

// entry point of isr
typedef VOID (*ISR_PROC)(VOID);

// entry point of state
typedef UINT STATE;
typedef STATE (*STATE_PROC)(VOID *puser_data, UINT32 type, VOID *pqueue_data);

// entry point of timer
typedef BOOL (*TIMER_PROC)(UINT16 id, VOID *parg);

//////////////////////////////////////  <  END  >  ///////////////////////////////////////

#ifdef __cplusplus
    } /* namespace ChaOS */
    } /* extern "C" */
#endif

#endif // __CO_DATA_TYPE_H__

